#pragma once

#include <QAbstractItemModel>
#include "Protocols/ShowableItem.h"
#include "Component/Displayer/qhexedit.h"

class QIcon;
class QModelIndex;
class QVariant;


class PacketTreeModel:public QAbstractItemModel
{
	Q_OBJECT
public:
	PacketTreeModel(QObject *parent = 0);
	~PacketTreeModel();

	void setRootNode(ShowableItem *showableitem);


	QModelIndex index(int row,int column,const QModelIndex &parent) const;
	QModelIndex parent(const QModelIndex &child) const;

	int rowCount(const QModelIndex &parent) const;
	int columnCount(const QModelIndex &parent) const{return 1;}
	QVariant data(const QModelIndex &index,int role)const;
	QVariant headerData(int section,
		Qt::Orientation orientation,
		int role) const;

	ShowableItem *getRootNode(){return rootNode;}
	QModelIndex   getSelectIndex(ShowableItem *item,int Begin,int Length);
	ShowableItem *getShowableItem(const QModelIndex &index){ return nodeFromIndex(index);}
		QHexEdit *qhe;
public slots:
	void setQHexEditSelection(const QModelIndex &index);

private:
	ShowableItem *nodeFromIndex(const QModelIndex &index) const;
	QVector<QIcon> icon;
	ShowableItem *rootNode;
};
